﻿function DeleteBook(bookID, categoryID, page) {
    var texTrans = $.iHouse.deleteBookDialog.confirmationtext;
    var text = texTrans.replace("{0}", bookID);
    var divString = "<div id='dialog' title='" + $.iHouse.deleteBookDialog.titletext + "'><p><span class='ui-icon ui-icon-alert' style='float:left; margin:0 7px 20px 0;'></span>"
            + text + "</p></div>";

    function okClick() {
        var absoluteUrl = Sys.loader.applicationPath + "Book/Delete/";
        var url = absoluteUrl + bookID + '?category=' + categoryID + '&page=' + page;

        $.post(url, deleteCallback);

        $(this).dialog('close');
    };

    function cancelClick() {
        $(this).dialog('close');
    };
    
    var dialogButton = {};
    dialogButton[$.iHouse.button.oktext] = okClick;
    dialogButton[$.iHouse.button.canceltext] = cancelClick;

    $(divString).dialog({
        bgiframe: true,
        resizable: false,
        height: 140,
        width: 350,
        modal: true,
        overlay: {
            backgroundColor: '#000',
            opacity: 0.5
        },
        buttons: dialogButton
    });

    function deleteCallback(result) {
         $('#bookShelf').html(result);
    }
};

function InitImagePreview() {
    //Larger thumbnail preview
    //http://www.sohtanaka.com/web-design/fancy-thumbnail-hover-effect-w-jquery/

    $("div.book-cover").hover(function () {
        $(this).css({ 'z-index': '10' });
        $(this).find('img').addClass("hover").stop()
		.animate({
		    marginTop: '-110px',
		    marginLeft: '-110px',
		    top: '50%',
		    left: '50%',
		    width: '174px',
		    height: '174px',
		    padding: '20px'
		}, 200);

    }, function() {
        $(this).css({ 'z-index': '0' });
        $(this).find('img').removeClass("hover").stop()
		.animate({
		    marginTop: '0',
		    marginLeft: '0',
		    top: '0',
		    left: '0',
		    width: '100px',
		    height: '100px',
		    padding: '0px'
		}, 400);
    });
};

function InitRateit(isReadonly) {
    $.fn.rateit.defaults = { min: 0, max: 5, step: 0.5, starwidth: 16, starheight: 16, readonly: isReadonly, resetable: true };

    var rateitIns = $('div.rateit');
    var scoreValue = $("#score").val();
    rateitIns.rateit({ value: scoreValue });

    if (!isReadonly) {
        $('div.rateit').bind('rated reset', function (e) {
            var ri = $(this);
            var value = ri.rateit('value');
            var bookID = $("#bookID").val();
            $('#score').val(value);
        });
    }
};

function InitBookCover() {
    $('.postim').each(function () {
        var actionContainer = $(this).find('.img-controller');

        if (actionContainer.length == 0)
            return;

        $(this).find('.bookcover').bind('mouseover', function () {
            actionContainer.show();
        });
        $(this).bind('mouseout', function () {
            actionContainer.hide();
        });
        actionContainer.bind('mouseover', function () {
            actionContainer.show();
        });
    })
}

function InitBookModals() {
    $('.detailModal').each(function () {
        $(this).colorbox({ iframe: true, width: "680px", height: "530px" });
    })

    $('.img-edit').each(function () {
        $(this).colorbox({ iframe: true, width: "600px", height: "660px" });
    })

    $('.img-upload').each(function () {
        $(this).colorbox({ iframe: true, width: "600px", height: "500px" });
    })
};